Skip to content

Conversation

@mcollina
Copy link
Member

Summary

  • Allows Connection header to contain comma-separated list of connection option tokens (header names) per RFC 7230 Section 6.1
  • Previously only close or keep-alive were accepted, now any valid HTTP token is allowed
  • Sets request.reset = true if close is present in the token list

Test plan

  • Added tests for close and keep-alive values
  • Added test for custom header name as connection option
  • Added test for comma-separated list of connection options
  • Added test for rejecting invalid tokens
  • All existing tests pass

Fixes #4774

…per RFC 7230

Per RFC 7230 Section 6.1, the Connection header can contain a
comma-separated list of connection option tokens (header names)
that should be removed by proxies before forwarding the message.

Previously, undici only allowed 'close' or 'keep-alive' as Connection
header values. This change allows any valid HTTP token as a connection
option, enabling RFC-compliant requests like:

  Connection: X-Custom-Header
  Connection: close, X-Custom-Header

Fixes: #4774
Signed-off-by: Matteo Collina <hello@matteocollina.com>
}

if (value === 'close') {
const tokens = value.split(',').map(t => t.trim().toLowerCase())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are iterating over them twice, can we do it at one pass?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could actually lowercase before split.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Refactored to lowercase before split and combined validation + close-check in a single loop.

- Lowercase before split as suggested
- Combine validation and close-check in single loop

Signed-off-by: Matteo Collina <hello@matteocollina.com>
The previous test used 'asd' as an invalid connection header value,
but 'asd' is a valid HTTP token per RFC 7230. Updated to use a truly
invalid value (token with spaces) instead.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.26%. Comparing base (cfd42c6) to head (8de106e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4775      +/-   ##
==========================================
- Coverage   93.27%   93.26%   -0.02%     
==========================================
  Files         109      109              
  Lines       34001    34009       +8     
==========================================
+ Hits        31713    31717       +4     
- Misses       2288     2292       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support sending Connection header with connection-specific header names per RFC 7230

4 participants